package org.skill.panel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.math.BigDecimal;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import com.updateNew.MyIsif;
import org.come.until.Util;
import org.skill.btn.SkillPromoteBtn;

import com.tool.btn.FormsOnOffBtn;
import com.tool.role.RoleData;
import com.tool.tcpimg.UIUtils;



/**
 * 提升技能点主要面板
 *
 * @author Administrator
 *
 */
public class SkillPromoteMainPanel extends JPanel {

    private JLabel currentPoin // 当前天枢点
            ,
            surplusPoint // 剩余天枢点
            , characterLevel // 当前人物等级
            , characterState // 当前人物境界
            , trainingProgress // 当前修炼进度
            , needExperience // 所需经验
            , currentExperience // 当前经验
            , needMoney // 所需金钱
            , currentMoney // 当前金钱
            , teacherGong // 当前师贡
            ;

    private SkillPromoteBtn promoteBtn // 提升修炼点按钮
            ,
            exchangeBtn // 一键兑换按钮
            ;

    private BigDecimal needMoneyNum = new BigDecimal("400000");
    private BigDecimal needExperienceNum = new BigDecimal("5000000");

    public SkillPromoteMainPanel() {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
        this.setPreferredSize(new Dimension(402, 465));
        this.setOpaque(false);
        this.setLayout(null);

        // 关闭按钮事件
        FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 83);
        offBtn.setBounds(364, 9, 25, 25);
        this.add(offBtn);

        // 组件初始化
        currentPoin = new JLabel("30");
        surplusPoint = new JLabel("30");
        characterLevel = new JLabel("3转140级");
        characterState = new JLabel("金丹期");
        trainingProgress = new JLabel("瓶颈");
        needExperience = new JLabel(needExperienceNum + "");
        currentExperience = new JLabel("1321321321");
        needMoney = new JLabel(needMoneyNum + "");
        currentMoney = new JLabel("165132sada165116");
        teacherGong = new JLabel("- -");
        promoteBtn = new SkillPromoteBtn("skin/8100226/newbutton/B22.png", 1, UIUtils.COLOR_BTNPUTONG, "提升修炼", 1, this);
        exchangeBtn = new SkillPromoteBtn("skin/8100226/newbutton/B22.png", 1, UIUtils.COLOR_BTNPUTONG, "一键兑换", 2, this);

        // 组件设置大小和方位
        this.currentPoin.setBounds(146, 50, 35, 18);
        this.surplusPoint.setBounds(334, 50, 35, 18);
        this.characterLevel.setBounds(182, 127, 150, 18);
        this.characterState.setBounds(182, 156, 150, 18);
        this.trainingProgress.setBounds(182, 188, 150, 18);
        this.needExperience.setBounds(182, 258, 150, 18);
        this.currentExperience.setBounds(182, 288, 150, 18);
        this.needMoney.setBounds(182, 318, 150, 18);
        this.currentMoney.setBounds(182, 300, 150, 18);
        this.teacherGong.setBounds(182, 380, 150, 18);
        this.promoteBtn.setBounds(210, 420, 99, 24);
        this.exchangeBtn.setBounds(94, 420, 99, 24);

        // 组件内容居中
        currentPoin.setHorizontalAlignment(SwingConstants.CENTER);
        surplusPoint.setHorizontalAlignment(SwingConstants.CENTER);
        characterLevel.setHorizontalAlignment(SwingConstants.CENTER);
        characterState.setHorizontalAlignment(SwingConstants.CENTER);
        trainingProgress.setHorizontalAlignment(SwingConstants.CENTER);
        needExperience.setHorizontalAlignment(SwingConstants.CENTER);
        currentExperience.setHorizontalAlignment(SwingConstants.CENTER);
        needMoney.setHorizontalAlignment(SwingConstants.CENTER);
        currentMoney.setHorizontalAlignment(SwingConstants.CENTER);
         teacherGong.setHorizontalAlignment(SwingConstants.CENTER);

        // 组件设置字体颜色
        currentPoin.setForeground(Color.white);
        surplusPoint.setForeground(Color.white);
        characterLevel.setForeground(Color.white);
        characterState.setForeground(Color.white);
        trainingProgress.setForeground(Color.white);
        needExperience.setForeground(Color.white);
        currentExperience.setForeground(Color.white);
        needMoney.setForeground(Color.white);
        currentMoney.setForeground(Color.white);
        teacherGong.setForeground(Color.white);

        // 组建设置字体
        currentPoin.setFont(UIUtils.TEXT_FONT1);
        surplusPoint.setFont(UIUtils.TEXT_FONT1);
        characterLevel.setFont(UIUtils.TEXT_FONT1);
        characterState.setFont(UIUtils.TEXT_FONT1);
        trainingProgress.setFont(UIUtils.TEXT_FONT1);
        needExperience.setFont(UIUtils.TEXT_FONT1);
        currentExperience.setFont(UIUtils.TEXT_FONT1);
        needMoney.setFont(UIUtils.TEXT_FONT1);
        // currentMoney.setFont(UIUtils.TEXT_FONT1);
        teacherGong.setFont(UIUtils.TEXT_FONT1);

        // 组件透明化
        currentPoin.setOpaque(false);
        surplusPoint.setOpaque(false);
        characterLevel.setOpaque(false);
        characterState.setOpaque(false);
        trainingProgress.setOpaque(false);
        needExperience.setOpaque(false);
        currentExperience.setOpaque(false);
        needMoney.setOpaque(false);
        // currentMoney.setOpaque(false);
        teacherGong.setOpaque(false);
        exchangeBtn.setOpaque(false);
        promoteBtn.setOpaque(false);

        // 添加组件
        this.add(currentPoin);
        this.add(surplusPoint);
        this.add(characterLevel);
        this.add(characterState);
        this.add(trainingProgress);
        this.add(needExperience);
        this.add(currentExperience);
        this.add(needMoney);
        // this.add(currentMoney);
        this.add(teacherGong);
        this.add(exchangeBtn);
        this.add(promoteBtn);
    } else {
        this.setPreferredSize(new Dimension(376, 466));
        this.setOpaque(false);
        this.setLayout(null);

        // 关闭按钮事件
        FormsOnOffBtn offBtn = new FormsOnOffBtn("img/xy2uiimg/8_jpg.button.btn_close.jpg", 1, 83);
        offBtn.setBounds(353, 0, 23, 23);
        this.add(offBtn);

        // 组件初始化
        currentPoin = new JLabel("30");
        surplusPoint = new JLabel("30");
        characterLevel = new JLabel("3转140级");
        characterState = new JLabel("金丹期");
        trainingProgress = new JLabel("瓶颈");
        needExperience = new JLabel(needExperienceNum + "");
        currentExperience = new JLabel("1321321321");
        needMoney = new JLabel(needMoneyNum + "");
        // currentMoney = new JLabel("165132sada165116");
        teacherGong = new JLabel("- -");
        promoteBtn = new SkillPromoteBtn("img/soaringSkill/提示修炼点w120,h78.png", 1, UIUtils.COLOR_BTNPUTONG, "", 1, this);
        exchangeBtn = new SkillPromoteBtn("img/soaringSkill/一键兑换w100,h78.png", 1, UIUtils.COLOR_BTNPUTONG, "", 2, this);

        // 组件设置大小和方位
        this.currentPoin.setBounds(122, 62, 35, 18);
        this.surplusPoint.setBounds(308, 63, 35, 18);
        this.characterLevel.setBounds(162, 139, 150, 18);
        this.characterState.setBounds(162, 169, 150, 18);
        this.trainingProgress.setBounds(162, 199, 150, 18);
        this.needExperience.setBounds(162, 268, 150, 18);
        this.currentExperience.setBounds(162, 299, 150, 18);
        this.needMoney.setBounds(162, 330, 150, 18);
        //this.currentMoney.setBounds(162, 361, 150, 18);
        this.promoteBtn.setBounds(180, 400, 120, 26);
        this.exchangeBtn.setBounds(64, 400, 100, 26);

        // 组件内容居中
        currentPoin.setHorizontalAlignment(SwingConstants.CENTER);
        surplusPoint.setHorizontalAlignment(SwingConstants.CENTER);
        characterLevel.setHorizontalAlignment(SwingConstants.CENTER);
        characterState.setHorizontalAlignment(SwingConstants.CENTER);
        trainingProgress.setHorizontalAlignment(SwingConstants.CENTER);
        needExperience.setHorizontalAlignment(SwingConstants.CENTER);
        currentExperience.setHorizontalAlignment(SwingConstants.CENTER);
        needMoney.setHorizontalAlignment(SwingConstants.CENTER);
        // currentMoney.setHorizontalAlignment(SwingConstants.CENTER);
        teacherGong.setHorizontalAlignment(SwingConstants.CENTER);

        // 组件设置字体颜色
        currentPoin.setForeground(Color.white);
        surplusPoint.setForeground(Color.white);
        characterLevel.setForeground(Color.white);
        characterState.setForeground(Color.white);
        trainingProgress.setForeground(Color.white);
        needExperience.setForeground(Color.white);
        currentExperience.setForeground(Color.white);
        needMoney.setForeground(Color.white);
        // currentMoney.setForeground(Color.white);
        teacherGong.setForeground(Color.white);

        // 组建设置字体
        currentPoin.setFont(UIUtils.TEXT_FONT1);
        surplusPoint.setFont(UIUtils.TEXT_FONT1);
        characterLevel.setFont(UIUtils.TEXT_FONT1);
        characterState.setFont(UIUtils.TEXT_FONT1);
        trainingProgress.setFont(UIUtils.TEXT_FONT1);
        needExperience.setFont(UIUtils.TEXT_FONT1);
        currentExperience.setFont(UIUtils.TEXT_FONT1);
        needMoney.setFont(UIUtils.TEXT_FONT1);
        // currentMoney.setFont(UIUtils.TEXT_FONT1);
        teacherGong.setFont(UIUtils.TEXT_FONT1);

        // 组件透明化
        currentPoin.setOpaque(false);
        surplusPoint.setOpaque(false);
        characterLevel.setOpaque(false);
        characterState.setOpaque(false);
        trainingProgress.setOpaque(false);
        needExperience.setOpaque(false);
        currentExperience.setOpaque(false);
        needMoney.setOpaque(false);
        // currentMoney.setOpaque(false);
        teacherGong.setOpaque(false);
        exchangeBtn.setOpaque(false);
        promoteBtn.setOpaque(false);

        // 添加组件
        this.add(currentPoin);
        this.add(surplusPoint);
        this.add(characterLevel);
        this.add(characterState);
        this.add(trainingProgress);
        this.add(needExperience);
        this.add(currentExperience);
        this.add(needMoney);
        // this.add(currentMoney);
        this.add(teacherGong);
        this.add(exchangeBtn);
        this.add(promoteBtn);

    }
    }

    /** 面板获取数据 */
    public void panelGetData(BigDecimal experience, int tsx, int tsExp, String lvl, String raceConfirm, int tsp,
            int realmMaxTSP) {
        this.getCurrentExperience().setText(experience.toString());
        this.getTrainingProgress().setText(tsx + "/" + tsExp);
        this.getCharacterLevel().setText(lvl);
        this.getCharacterState().setText(raceConfirm == null ? "- -" : raceConfirm);
        this.getCurrentPoin().setText(tsp + "");
        this.getSurplusPoint().setText((realmMaxTSP - tsp) + "");
    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        if (icon == null) {
            icon = new ImageIcon("inkImg/old/background/S38.png");
        }
        g.drawImage(icon.getImage(), 0, 0, 402, 465, this);
        Util.drawMoney(g, drawCenteredString(g, RoleData.getRoleData().getLoginResult().getGold().toString(), 182, 162, UIUtils.TEXT_FONT1), 363);
        } else {
            // TODO Auto-generated method stub
            super.paintComponent(g);
            if (icon == null) {
                icon = new ImageIcon("img/soaringSkill/提升修炼点w376，h466.png");
            }
            g.drawImage(icon.getImage(), 0, 0, 376, 466, this);
            Util.drawMoney(g, drawCenteredString(g, RoleData.getRoleData().getLoginResult().getGold().toString(), 141, 162, UIUtils.TEXT_FONT1), 375);
        }
    }

    /**
     * 居中算法
     *
     * @param g
     *            The Graphics instance.
     * @param text
     *            The String to draw.
     * @param
     *
     */
    public int drawCenteredString(Graphics g, String text, int getX, int lonX, Font font) {
        // Get the FontMetrics
        FontMetrics metrics = g.getFontMetrics(font);
        // Determine the X coordinate for the text
        int x = lonX + (getX - metrics.stringWidth(text)) / 2;
        return x;

    }

    /** 当前天枢点 */
    public JLabel getCurrentPoin() {
        return currentPoin;
    }

    public void setCurrentPoin(JLabel currentPoin) {
        this.currentPoin = currentPoin;
    }

    public JLabel getSurplusPoint() {
        return surplusPoint;
    }

    public void setSurplusPoint(JLabel surplusPoint) {
        this.surplusPoint = surplusPoint;
    }

    public JLabel getCharacterLevel() {
        return characterLevel;
    }

    public void setCharacterLevel(JLabel characterLevel) {
        this.characterLevel = characterLevel;
    }

    public JLabel getCharacterState() {
        return characterState;
    }

    public void setCharacterState(JLabel characterState) {
        this.characterState = characterState;
    }

    public JLabel getTrainingProgress() {
        return trainingProgress;
    }

    public void setTrainingProgress(JLabel trainingProgress) {
        this.trainingProgress = trainingProgress;
    }

    public JLabel getNeedExperience() {
        return needExperience;
    }

    public void setNeedExperience(JLabel needExperience) {
        this.needExperience = needExperience;
    }

    public JLabel getCurrentExperience() {
        return currentExperience;
    }

    public void setCurrentExperience(JLabel currentExperience) {
        this.currentExperience = currentExperience;
    }

    public JLabel getNeedMoney() {
        return needMoney;
    }

    public void setNeedMoney(JLabel needMoney) {
        this.needMoney = needMoney;
    }

    public SkillPromoteBtn getPromoteBtn() {
        return promoteBtn;
    }

    public void setPromoteBtn(SkillPromoteBtn promoteBtn) {
        this.promoteBtn = promoteBtn;
    }

    public SkillPromoteBtn getExchangeBtn() {
        return exchangeBtn;
    }

    public void setExchangeBtn(SkillPromoteBtn exchangeBtn) {
        this.exchangeBtn = exchangeBtn;
    }

    public ImageIcon getIcon() {
        return icon;
    }

    public void setIcon(ImageIcon icon) {
        this.icon = icon;
    }

    public BigDecimal getNeedMoneyNum() {
        return needMoneyNum;
    }

    public void setNeedMoneyNum(BigDecimal needMoneyNum) {
        this.needMoneyNum = needMoneyNum;
    }

    public BigDecimal getNeedExperienceNum() {
        return needExperienceNum;
    }

    public void setNeedExperienceNum(BigDecimal needExperienceNum) {
        this.needExperienceNum = needExperienceNum;
    }

    public JLabel getTeacherGong() {
        return teacherGong;
    }

    public void setTeacherGong(JLabel teacherGong) {
        this.teacherGong = teacherGong;
    }

}
